package com.aipp.mall.common.utils;

import com.aipp.mall.common.exception.ServerException;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.CharsetUtil;
import org.dromara.hutool.crypto.SecureUtil;
import org.dromara.hutool.crypto.symmetric.AES;

/**
 * aes加密工具
 * @author Administrator
 */
public class AesCryptoUtils {

    public static String encrypt(String key, String content) {
        if (StrUtil.isBlank(key) || StrUtil.isBlank(content)) {
            throw new ServerException("错误");
        }
        AES aes = SecureUtil.aes(key.getBytes());
        return aes.encryptHex(content);
    }

    public static String decrypt(String key, String content) {
        if (StrUtil.isBlank(key) || StrUtil.isBlank(content)) {
            throw new ServerException("错误");
        }
        AES aes = SecureUtil.aes(key.getBytes());
        return aes.decryptStr(content, CharsetUtil.UTF_8);
    }
}
